package com.tanjun.thirdservice.web.biz.impl;

import com.tanjun.common.utils.ConvertUntil;
import com.tanjun.thirdservice.request.WxCode2PhoneVo;
import com.tanjun.thirdservice.request.WxCode2UserVo;
import com.tanjun.thirdservice.response.WxCode2PhoneDto;
import com.tanjun.thirdservice.response.WxCode2UserDto;
import com.tanjun.thirdservice.web.biz.WxUserBiz;
import com.tanjun.thirdservice.web.service.wx.WxUserService;
import com.tanjun.thirdservice.web.service.wx.request.WxCodeToPhoneRequest;
import com.tanjun.thirdservice.web.service.wx.request.WxCodeToUserRequest;
import com.tanjun.thirdservice.web.service.wx.response.WxCode2PhoneResponse;
import com.tanjun.thirdservice.web.service.wx.response.WxCode2UserResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxUserBizImpl implements WxUserBiz {
    @Autowired
    private WxUserService wxUserService;

    /**
     * 微信 将code换成openId
     *
     * @param paramVo
     * @return
     */
    @Override
    public WxCode2UserDto jscode2session(WxCode2UserVo paramVo) {
        WxCode2UserResponse response = wxUserService.jscode2session(ConvertUntil.convert(paramVo, WxCodeToUserRequest.class));
        return ConvertUntil.convert(response, WxCode2UserDto.class);
    }

    /**
     * 获取微信手机号
     *
     * @param paramVo
     * @return
     */
    @Override
    public WxCode2PhoneDto getPhoneNumber(WxCode2PhoneVo paramVo) {
        WxCode2PhoneResponse response = wxUserService.getPhoneNumber(ConvertUntil.convert(paramVo, WxCodeToPhoneRequest.class));
        WxCode2PhoneDto dto = new WxCode2PhoneDto();
        dto.setPhone(response.getPhoneInfo().getPhoneNumber());
        return dto;
    }
}
